
pkgname=git
pkgver=2.18.0
pkgrel=1
pkgdesc="Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency."
arch=('x86_64')
url="http://git-scm.com/"
license=('GPL2')
depends=('curl' 'expat>=2.0' 'perl-error' 'perl' 'pcre')
makedepends=('python2')
optdepends=('tk: gitk and git gui'
            'python2: various helper scripts'
            'subversion: git svn')
#install="git.install"
source=("https://www.kernel.org/pub/software/scm/git/git-${pkgver}.tar.xz"
        "https://www.kernel.org/pub/software/scm/git/git-manpages-${pkgver}.tar.xz"
        'git-daemon@.service'
        'git-daemon.socket')
sha256sums=('8b40be383a603147ae29337136c00d1c634bdfdc169a30924a024596a7e30e92'
            '9ae3be95e63379597164c79c9018e84b7ef6964da923e5689dbc307693266096'
            '3bc3250d9e04b05c41975c01f85f512d3386d60b41475cbc7292bc88148852f6'
            'ac4c90d62c44926e6d30d18d97767efc901076d4e0283ed812a349aece72f203')

build() {
  cd ${pkgname}-${pkgver}
  
  make prefix=/usr \
       gitexecdir=/usr/lib/git-core \
       USE_LIBPCRE1=1 \
       NO_CROSS_DIRECTORY_HARDLINKS=1 \
       all
}

check() {
  cd ${pkgname}-${pkgver}

  rm t/t8005-blame-i18n.sh
  local jobs="$(expr "$MAKEFLAGS" : '.*\(-j[0-9]*\).*')"
  #jobs='-j1'
  mkdir -p /dev/shm/git-test
  
  make prefix=/usr \
       gitexecdir=/usr/lib/git-core \
       USE_LIBPCRE1=1 \
       NO_CROSS_DIRECTORY_HARDLINKS=1 \
       NO_SVN_TESTS=y \
       DEFAULT_TEST_TARGET=prove \
       GIT_PROVE_OPTS="${jobs} -Q" \
       GIT_TEST_OPTS="--root=/dev/shm/git-test" \
       test
}

package() {
  cd ${pkgname}-${pkgver}
  make prefix=/usr \
       gitexecdir=/usr/lib/git-core \
       USE_LIBPCRE1=1 \
       NO_CROSS_DIRECTORY_HARDLINKS=1 \
       INSTALLDIRS=vendor DESTDIR=${pkgdir} install 

  # bash completion
  mkdir -p ${pkgdir}/usr/share/bash-completion/completions/
  install -m644 ./contrib/completion/git-completion.bash ${pkgdir}/usr/share/bash-completion/completions/git
  # git prompt
  mkdir -p ${pkgdir}/usr/share/git/
  install -m644 ./contrib/completion/git-prompt.sh ${pkgdir}/usr/share/git/git-prompt.sh
  # more contrib stuff
  cp -a ./contrib/* ${pkgdir}/usr/share/git/

  # manpages
  for mansect in man1 man5 man7; do
    for manpage in ${srcdir}/${mansect}/*; do
      install -D -m644 ${manpage} ${pkgdir}/usr/share/man/${mansect}/$(basename ${manpage})
    done
  done

  # remove perllocal.pod, .packlist, and empty directories.
  rm -rf ${pkgdir}/usr/lib/perl5

  # systemd 
  install -D -m644 ${srcdir}/git-daemon@.service ${pkgdir}/usr/lib/systemd/system/git-daemon@.service
  install -D -m644 ${srcdir}/git-daemon.socket ${pkgdir}/usr/lib/systemd/system/git-daemon.socket
}

